package com.springcloud.eshop.product.service;

import com.alibaba.fastjson.JSON;
import com.springcloud.eshop.message.DataChangeMessage;
import com.springcloud.eshop.product.rabbitmq.RabbitmqProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Desc:
 * @Date: 2020-07-02
 * @Version:v1.0
 */
@Service
public class SendMQService {
    private Logger logger = LoggerFactory.getLogger(SendMQService.class);

    @Autowired
    private RabbitmqProducer rabbitmqProducer;

    /**
     * @Desc: 发送消息
     * @Param dataChangeMessage
     * @Return boolean
     * @Date: 2020/7/2
     */
    public boolean sendMessage(DataChangeMessage dataChangeMessage) {
        logger.info("SendMQService.sendMessage start, 发送数据变更消息，dataType:{}, eventType:{},  dataChangeMessage: {}", dataChangeMessage.getDataType(), dataChangeMessage.getEventType(), JSON.toJSONString(dataChangeMessage));
        rabbitmqProducer.sendMessage(JSON.toJSONString(dataChangeMessage));
        return true;
    }
}
